<?php
$event_id = $_REQUEST['event_id'];

if ($_POST['Submit']) {
	$event_name = $_POST['event_name'];
	$short_description = $_POST['short_description'];
	$registration_start = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['registration_start']));
	$registration_end = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['registration_end']));
	$registration_limit = $_POST['registration_limit'];
	$event_start = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['event_start'] . " " . $_POST['event_start_hour'] . ":" . $_POST['event_start_minute'] . " " . $_POST['event_start_ap']));
	$event_end = $event_start;
	//$event_end = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['event_end'] . " " . $_POST['event_end_hour'] . ":" . $_POST['event_end_minute'] . " " . $_POST['event_end_ap']));
	$listing_status = $_POST['listing_status'];
	$address1 = $_POST['address1'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zip = $_POST['zip'];
	$login_required = $_POST['login_required'] == "Y" ? "Y" : "N";

	//update event
	$wpdb->query("UPDATE $em_event_table set event_name = '$event_name', short_description = '$short_description', "
			. "registration_start = '$registration_start', registration_end = '$registration_end', registration_limit = '$registration_limit', "
			. "event_start = '$event_start', event_end = '$event_end', listing_status = '$listing_status', address1 = '$address1', "
			. "address2 = '$address2', city = '$city', state = '$state', zip = '$zip', login_required = '$login_required' where id = '$event_id'");
	?>
	<div id="message" class="updated fade"><p><strong>Event Saved, <a href="<?php echo EM_URL ?>event-list.php">return to event list.</a></strong></p></div>
	<?php
}

$event = $wpdb->get_row("SELECT * from $em_event_table where id = '$event_id'");
?>

<div class="wrap">

<?php include('includes/admin-event-form.php') ?>

<h3>Linking to this event</h3>
<p>When linking to the registration page in a post or page within WordPress, use this tag:
	<blockquote><code>em-link[<?php echo $event->id ?>]</code>  </blockquote></p>

<p>You can optionally control the display text that is generated in the link by adding some text afer the event ID.
	<blockquote><code>em-link[<?php echo $event->id ?>:Click here to register]</code> will generate: <a href="<?php echo em_event_url($event->id) ?>">Click here to register</a> </blockquote></p>

<p>When linking to the registration page outside of this website use this URL: <blockquote><code><?php echo em_event_url($event->id) ?></code></blockquote></p>

</div>